﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NativeDataOperation.Business;
using NativeDataOperation.Interfaces;
using WebFoundation;
using WebFoundation.Data;

namespace DDHDeepTunnel.EquipmentManagement.Data
{
    public class SqlProcedureQueryDAO<T> : WritableDAO<T> where T : class
    {
        public DbManager _dbManager;
        public IDbTransaction _transaction;
        public SqlProcedureQueryDAO(DbManager dbManager, IDbTransaction transaction = null)
            : base(dbManager)
        {
            _dbManager = dbManager;
            _transaction = transaction;
        }

        public IEnumerable<T> QueryParamsStoredProcedure<T>(string storedProcedureName,
            List<ProcedureParams> procedureParamses = null)
            where T : class
        {
            var sqlProcedure = new DataBaseProcedure();
            IEnumerable<T> result = null;
            try
            {
                result = sqlProcedure.QueryParamsStoredProcedure<T>(storedProcedureName,
                    this._dbManager, procedureParamses);
            }
            catch(Exception ex)
            {
                this.GetType().LogDebug(ex,
                        "<[DDHDeepTunnel.EquipmentManagement.Data/SqlProcedureQueryDAO<T>/QueryParamsStoredProcedure<T>, Exception found.] StoredProcedureName=[" + storedProcedureName + "]> Error:" +
                        ex.Message);
            }
            return result;
        }

        public IEnumerable<T> QueryMultipleParamsStoredProcedure<T>(string storedProcedureName,
            out List<DataBaseSystemPaging> dataBaseSystemPagings,
            List<ProcedureParams> procedureParamses = null)
            where T : class
        {
            var sqlProcedure = new DataBaseProcedure();
            IEnumerable<T> result = null;
            result = sqlProcedure.QueryMultipleParamsStoredProcedure<T>(storedProcedureName, out dataBaseSystemPagings,
                this._dbManager, procedureParamses);
            return result;
        }
    }
}
